package com.kzd.sdk.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.kzd.sdk.callback.KZD_OnClickListener;
import com.kzd.sdk.utils.AppUtils;

public class KZD_AccountSwitchDialog extends Dialog {

    private KZD_OnClickListener mOnClickListener;

    public KZD_AccountSwitchDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(AppUtils.getLayoutId(getContext(), "kzd_dialog_account_switch"));
        initView();
    }

    @Override
    protected void onStart() {
        super.onStart();
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(params);
        getWindow().getDecorView()
                .setPadding((0), (0), (0), (0));
        getWindow().getDecorView()
                .setBackgroundColor(Color.TRANSPARENT);
        getWindow().setGravity(Gravity.BOTTOM);
    }


    private void initView() {
        findViewById(AppUtils.getId(getContext(), "tvAccountSwitchCancel"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        cancel();
                    }
                });
        findViewById(AppUtils.getId(getContext(), "tvAccountSwitchConfirm"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        cancel();
                        if (mOnClickListener != null) {
                            mOnClickListener.onClick(v);
                        }
                    }
                });
    }

    public void setOnClickListener(KZD_OnClickListener listener) {
        this.mOnClickListener = listener;
    }
}
